<template>
    <el-row :gutter="10">
        <el-col :span="7">
            <el-divider><span class="divider-css">选择接诊信息</span>
                <el-tooltip class="box-item" content="请先选择需要查看的患者就诊信息" effect="dark" placement="top">
                    <i-ep-infoFilled class="infoFilled-style"/>
                </el-tooltip>
            </el-divider>
            <el-button class="mb5" plain style="float: right;" type="primary"
                       @click="listClinicMasterFun(props.patientId)">
                <template #icon>
                    <i-ep-search/>
                </template>
                刷新
            </el-button>
            <el-table :border="true" :data="patientList" :header-cell-style="$headerCellStyle" :stripe="true" height="400"
                      highlight-current-row @row-click="patientRowClick">
                <el-table-column :align="'center'" :show-overflow-tooltip="true" label="门诊号" prop="clinicNo"
                                 width="110"/>
                <el-table-column :align="'center'" :show-overflow-tooltip="true" label="患者姓名" prop="name"/>
                <el-table-column :align="'center'" :show-overflow-tooltip="true" label="接诊科室" prop="deptName"
                                 width="80"/>
                <el-table-column :align="'center'" :show-overflow-tooltip="true" label="接诊医生" prop="doctorName"
                                 width="80"/>
                <el-table-column :align="'center'" :show-overflow-tooltip="true" label="接诊时间" prop="visitDate"
                                 width="100"/>
            </el-table>
        </el-col>
        <el-col :span="17">
            <el-divider><span class="divider-css">选择病历信息</span>
                <el-tooltip class="box-item" content="选择好患者就诊信息后，可以查看此次就诊书写的病历信息，点击【病历引用】可直接引用病历信息"
                            effect="dark"
                            placement="top">
                    <i-ep-infoFilled class="infoFilled-style"/>
                </el-tooltip>
            </el-divider>
            <medical-record-history-item ref="medicalRecordHistoryItemRef" @history-quote="historyQuote"/>
        </el-col>
    </el-row>
</template>

<script lang="ts" setup>
import {useDictStoreHook} from "@/store/modules/dict";
import {listClinicMaster} from "@/api/patient/clinicMaster.ts";
import MedicalRecordHistoryItem from "./medicalRecordHistoryItem.vue";

const dictStore = useDictStoreHook();
const emits = defineEmits(["historyQuote"])
const props = defineProps({
    patientId: {
        type: String,
        default: ""
    },
    refreshKey: {
        type: Number,
        default: 0
    },
    orgId: {
        type: String,
        default: ""
    }
})
// 患者就诊记录id
const clinicId = ref<string>("")
// 已选择的患者处方主表信息
const applyId = ref<string>("")
// 患者list
const patientList = ref<any>([])
// 主表id 集合
const applyIds = ref<any>([])
// 引用按钮是否禁用
const applyDisabled = ref<boolean>(true)
// 明细信息按钮是否禁用
const itemDisabled = ref<boolean>(true)
// 历史病历
const medicalRecordHistoryItemRef = ref()
const applyTableRef = ref()
watch(() => props.refreshKey, () => {
    listClinicMasterFun(props.patientId)
})

listClinicMasterFun(props.patientId)

/**
 * 获取patientId相同的患者列表
 * @param nowValue
 */
function listClinicMasterFun(nowValue: string) {
    patientList.value = []
    const param = {
        patientId: nowValue
    }
    listClinicMaster(param).then((res: resType) => {
        patientList.value = res.data
    })
}

/**
 * 患者列表点击事件
 */
function patientRowClick(row: any) {
    clinicId.value = row.id
    medicalRecordHistoryItemRef.value.rowClick(row)
}

/**
 * 处方信息引用事件
 * @param form
 * @param type 1 追加 | 2覆盖
 */
function historyQuote(form: any, type: string) {
    emits("historyQuote", form, type)
}

/**
 * 处方明细信息引用事件
 */
function itemQuote() {
}
</script>

<style scoped>
.infoFilled-style {
    margin-bottom: -3px;
}
</style>
